/**
 * @brief scheduling functionality
 * @author Gilad Avidov
 *
 * fork() creates a new task with a given function pointer. unlike Unix
 *        it returns ones for the caller. the new task is saved in the scheduler.
 *		  first call to fork creates the highest priority task, next call is next
 *        priority.
 * sched_sleep_ticks() support for periodic tasks. sends the current task to sleep
 *        and wakes up the highest priority task in a ready state.
 * sched_tick() is called by a periodic timer to decrement the time left to sleep of
 *        sleeping tasks. may result in a context switch in the case that a task
 *        with higher priority than the current one, reaches zero sleep time and thus
 *        wakeup.
 */

#ifndef SCHED_H_INCLUDED
#define SCHED_H_INCLUDED

#define SCHED_MAX_TASSKS     		(4)
#define STACK_BEGIN     			(0x35)
#define STACK_END       			(0xFF)
#define STACK_SIZE      			((STACK_END) - (STACK_BEGIN))

/* call first */
void sched_init();

/* @return positive task id on success or negative error */
char sched_fork(void (*task)(void));

/* @return will never return */
void sched_run();

/* tick=1ms, can adjust at time.h */
void sched_sleep_ticks(unsigned short ticks);

/* called by periodic clock */
void sched_tick(void);

/* print task list */
void sched_dump_state(void);

/* dumps full stack and state */
void sched_dump_full_state(void);


void usleep(unsigned short usec);







#endif // SCHED_H_INCLUDED
